home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / numbers.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  13KB  |  431 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Abstract Base Classes (ABCs) for numbers, according to PEP 3141.
  5.  
  6. TODO: Fill out more detailed documentation on the operators.'''
  7. from __future__ import division
  8. from abc import ABCMeta, abstractmethod, abstractproperty
  9. __all__ = [
  10.     'Number',
  11.     'Complex',
  12.     'Real',
  13.     'Rational',
  14.     'Integral']
  15.  
  16. class Number(object):
  17.     '''All numbers inherit from this class.
  18.  
  19.     If you just want to check if an argument x is a number, without
  20.     caring what kind, use isinstance(x, Number).
  21.     '''
  22.     __metaclass__ = ABCMeta
  23.     __slots__ = ()
  24.     __hash__ = None
  25.  
  26.  
  27. class Complex(Number):
  28.     """Complex defines the operations that work on the builtin complex type.
  29.  
  30.     In short, those are: a conversion to complex, .real, .imag, +, -,
  31.     *, /, abs(), .conjugate, ==, and !=.
  32.  
  33.     If it is given heterogenous arguments, and doesn't have special
  34.     knowledge about them, it should fall back to the builtin complex
  35.     type as described below.
  36.     """
  37.     __slots__ = ()
  38.     
  39.     def __complex__(self):
  40.         '''Return a builtin complex instance. Called for complex(self).'''
  41.         pass
  42.  
  43.     __complex__ = abstractmethod(__complex__)
  44.     
  45.     def __nonzero__(self):
  46.         '''True if self != 0. Called for bool(self).'''
  47.         return self != 0
  48.  
  49.     
  50.     def real(self):
  51.         '''Retrieve the real component of this number.
  52.  
  53.         This should subclass Real.
  54.         '''
  55.         raise NotImplementedError
  56.  
  57.     real = abstractproperty(real)
  58.     
  59.     def imag(self):
  60.         '''Retrieve the imaginary component of this number.
  61.  
  62.         This should subclass Real.
  63.         '''
  64.         raise NotImplementedError
  65.  
  66.     imag = abstractproperty(imag)
  67.     
  68.     def __add__(self, other):
  69.         '''self + other'''
  70.         raise NotImplementedError
  71.  
  72.     __add__ = abstractmethod(__add__)
  73.     
  74.     def __radd__(self, other):
  75.         '''other + self'''
  76.         raise NotImplementedError
  77.  
  78.     __radd__ = abstractmethod(__radd__)
  79.     
  80.     def __neg__(self):
  81.         '''-self'''
  82.         raise NotImplementedError
  83.  
  84.     __neg__ = abstractmethod(__neg__)
  85.     
  86.     def __pos__(self):
  87.         '''+self'''
  88.         raise NotImplementedError
  89.  
  90.     __pos__ = abstractmethod(__pos__)
  91.     
  92.     def __sub__(self, other):
  93.         '''self - other'''
  94.         return self + -other
  95.  
  96.     
  97.     def __rsub__(self, other):
  98.         '''other - self'''
  99.         return -self + other
  100.  
  101.     
  102.     def __mul__(self, other):
  103.         '''self * other'''
  104.         raise NotImplementedError
  105.  
  106.     __mul__ = abstractmethod(__mul__)
  107.     
  108.     def __rmul__(self, other):
  109.         '''other * self'''
  110.         raise NotImplementedError
  111.  
  112.     __rmul__ = abstractmethod(__rmul__)
  113.     
  114.     def __div__(self, other):
  115.         '''self / other without __future__ division
  116.  
  117.         May promote to float.
  118.         '''
  119.         raise NotImplementedError
  120.  
  121.     __div__ = abstractmethod(__div__)
  122.     
  123.     def __rdiv__(self, other):
  124.         '''other / self without __future__ division'''
  125.         raise NotImplementedError
  126.  
  127.     __rdiv__ = abstractmethod(__rdiv__)
  128.     
  129.     def __truediv__(self, other):
  130.         '''self / other with __future__ division.
  131.  
  132.         Should promote to float when necessary.
  133.         '''
  134.         raise NotImplementedError
  135.  
  136.     __truediv__ = abstractmethod(__truediv__)
  137.     
  138.     def __rtruediv__(self, other):
  139.         '''other / self with __future__ division'''
  140.         raise NotImplementedError
  141.  
  142.     __rtruediv__ = abstractmethod(__rtruediv__)
  143.     
  144.     def __pow__(self, exponent):
  145.         '''self**exponent; should promote to float or complex when necessary.'''
  146.         raise NotImplementedError
  147.  
  148.     __pow__ = abstractmethod(__pow__)
  149.     
  150.     def __rpow__(self, base):
  151.         '''base ** self'''
  152.         raise NotImplementedError
  153.  
  154.     __rpow__ = abstractmethod(__rpow__)
  155.     
  156.     def __abs__(self):
  157.         '''Returns the Real distance from 0. Called for abs(self).'''
  158.         raise NotImplementedError
  159.  
  160.     __abs__ = abstractmethod(__abs__)
  161.     
  162.     def conjugate(self):
  163.         '''(x+y*i).conjugate() returns (x-y*i).'''
  164.         raise NotImplementedError
  165.  
  166.     conjugate = abstractmethod(conjugate)
  167.     
  168.     def __eq__(self, other):
  169.         '''self == other'''
  170.         raise NotImplementedError
  171.  
  172.     __eq__ = abstractmethod(__eq__)
  173.     
  174.     def __ne__(self, other):
  175.         '''self != other'''
  176.         return not (self == other)
  177.  
  178.  
  179. Complex.register(complex)
  180.  
  181. class Real(Complex):
  182.     '''To Complex, Real adds the operations that work on real numbers.
  183.  
  184.     In short, those are: a conversion to float, trunc(), divmod,
  185.     %, <, <=, >, and >=.
  186.  
  187.     Real also provides defaults for the derived operations.
  188.     '''
  189.     __slots__ = ()
  190.     
  191.     def __float__(self):
  192.         '''Any Real can be converted to a native float object.
  193.  
  194.         Called for float(self).'''
  195.         raise NotImplementedError
  196.  
  197.     __float__ = abstractmethod(__float__)
  198.     
  199.     def __trunc__(self):
  200.         '''trunc(self): Truncates self to an Integral.
  201.  
  202.         Returns an Integral i such that:
  203.           * i>0 iff self>0;
  204.           * abs(i) <= abs(self);
  205.           * for any Integral j satisfying the first two conditions,
  206.             abs(i) >= abs(j) [i.e. i has "maximal" abs among those].
  207.         i.e. "truncate towards 0".
  208.         '''
  209.         raise NotImplementedError
  210.  
  211.     __trunc__ = abstractmethod(__trunc__)
  212.     
  213.     def __divmod__(self, other):
  214.         '''divmod(self, other): The pair (self // other, self % other).
  215.  
  216.         Sometimes this can be computed faster than the pair of
  217.         operations.
  218.         '''
  219.         return (self // other, self % other)
  220.  
  221.     
  222.     def __rdivmod__(self, other):
  223.         '''divmod(other, self): The pair (self // other, self % other).
  224.  
  225.         Sometimes this can be computed faster than the pair of
  226.         operations.
  227.         '''
  228.         return (other // self, other % self)
  229.  
  230.     
  231.     def __floordiv__(self, other):
  232.         '''self // other: The floor() of self/other.'''
  233.         raise NotImplementedError
  234.  
  235.     __floordiv__ = abstractmethod(__floordiv__)
  236.     
  237.     def __rfloordiv__(self, other):
  238.         '''other // self: The floor() of other/self.'''
  239.         raise NotImplementedError
  240.  
  241.     __rfloordiv__ = abstractmethod(__rfloordiv__)
  242.     
  243.     def __mod__(self, other):
  244.         '''self % other'''
  245.         raise NotImplementedError
  246.  
  247.     __mod__ = abstractmethod(__mod__)
  248.     
  249.     def __rmod__(self, other):
  250.         '''other % self'''
  251.         raise NotImplementedError
  252.  
  253.     __rmod__ = abstractmethod(__rmod__)
  254.     
  255.     def __lt__(self, other):
  256.         '''self < other
  257.  
  258.         < on Reals defines a total ordering, except perhaps for NaN.'''
  259.         raise NotImplementedError
  260.  
  261.     __lt__ = abstractmethod(__lt__)
  262.     
  263.     def __le__(self, other):
  264.         '''self <= other'''
  265.         raise NotImplementedError
  266.  
  267.     __le__ = abstractmethod(__le__)
  268.     
  269.     def __complex__(self):
  270.         '''complex(self) == complex(float(self), 0)'''
  271.         return complex(float(self))
  272.  
  273.     
  274.     def real(self):
  275.         '''Real numbers are their real component.'''
  276.         return +self
  277.  
  278.     real = property(real)
  279.     
  280.     def imag(self):
  281.         '''Real numbers have no imaginary component.'''
  282.         return 0
  283.  
  284.     imag = property(imag)
  285.     
  286.     def conjugate(self):
  287.         '''Conjugate is a no-op for Reals.'''
  288.         return +self
  289.  
  290.  
  291. Real.register(float)
  292.  
  293. class Rational(Real):
  294.     '''.numerator and .denominator should be in lowest terms.'''
  295.     __slots__ = ()
  296.     
  297.     def numerator(self):
  298.         raise NotImplementedError
  299.  
  300.     numerator = abstractproperty(numerator)
  301.     
  302.     def denominator(self):
  303.         raise NotImplementedError
  304.  
  305.     denominator = abstractproperty(denominator)
  306.     
  307.     def __float__(self):
  308.         '''float(self) = self.numerator / self.denominator
  309.  
  310.         It\'s important that this conversion use the integer\'s "true"
  311.         division rather than casting one side to float before dividing
  312.         so that ratios of huge integers convert without overflowing.
  313.  
  314.         '''
  315.         return self.numerator / self.denominator
  316.  
  317.  
  318.  
  319. class Integral(Rational):
  320.     '''Integral adds a conversion to long and the bit-string operations.'''
  321.     __slots__ = ()
  322.     
  323.     def __long__(self):
  324.         '''long(self)'''
  325.         raise NotImplementedError
  326.  
  327.     __long__ = abstractmethod(__long__)
  328.     
  329.     def __index__(self):
  330.         '''Called whenever an index is needed, such as in slicing'''
  331.         return long(self)
  332.  
  333.     
  334.     def __pow__(self, exponent, modulus = None):
  335.         """self ** exponent % modulus, but maybe faster.
  336.  
  337.         Accept the modulus argument if you want to support the
  338.         3-argument version of pow(). Raise a TypeError if exponent < 0
  339.         or any argument isn't Integral. Otherwise, just implement the
  340.         2-argument version described in Complex.
  341.         """
  342.         raise NotImplementedError
  343.  
  344.     __pow__ = abstractmethod(__pow__)
  345.     
  346.     def __lshift__(self, other):
  347.         '''self << other'''
  348.         raise NotImplementedError
  349.  
  350.     __lshift__ = abstractmethod(__lshift__)
  351.     
  352.     def __rlshift__(self, other):
  353.         '''other << self'''
  354.         raise NotImplementedError
  355.  
  356.     __rlshift__ = abstractmethod(__rlshift__)
  357.     
  358.     def __rshift__(self, other):
  359.         '''self >> other'''
  360.         raise NotImplementedError
  361.  
  362.     __rshift__ = abstractmethod(__rshift__)
  363.     
  364.     def __rrshift__(self, other):
  365.         '''other >> self'''
  366.         raise NotImplementedError
  367.  
  368.     __rrshift__ = abstractmethod(__rrshift__)
  369.     
  370.     def __and__(self, other):
  371.         '''self & other'''
  372.         raise NotImplementedError
  373.  
  374.     __and__ = abstractmethod(__and__)
  375.     
  376.     def __rand__(self, other):
  377.         '''other & self'''
  378.         raise NotImplementedError
  379.  
  380.     __rand__ = abstractmethod(__rand__)
  381.     
  382.     def __xor__(self, other):
  383.         '''self ^ other'''
  384.         raise NotImplementedError
  385.  
  386.     __xor__ = abstractmethod(__xor__)
  387.     
  388.     def __rxor__(self, other):
  389.         '''other ^ self'''
  390.         raise NotImplementedError
  391.  
  392.     __rxor__ = abstractmethod(__rxor__)
  393.     
  394.     def __or__(self, other):
  395.         '''self | other'''
  396.         raise NotImplementedError
  397.  
  398.     __or__ = abstractmethod(__or__)
  399.     
  400.     def __ror__(self, other):
  401.         '''other | self'''
  402.         raise NotImplementedError
  403.  
  404.     __ror__ = abstractmethod(__ror__)
  405.     
  406.     def __invert__(self):
  407.         '''~self'''
  408.         raise NotImplementedError
  409.  
  410.     __invert__ = abstractmethod(__invert__)
  411.     
  412.     def __float__(self):
  413.         '''float(self) == float(long(self))'''
  414.         return float(long(self))
  415.  
  416.     
  417.     def numerator(self):
  418.         '''Integers are their own numerators.'''
  419.         return +self
  420.  
  421.     numerator = property(numerator)
  422.     
  423.     def denominator(self):
  424.         '''Integers have a denominator of 1.'''
  425.         return 1
  426.  
  427.     denominator = property(denominator)
  428.  
  429. Integral.register(int)
  430. Integral.register(long)
  431.